package com.hanbang.gycatering.property;

import org.json.JSONException;
import org.json.JSONObject;
import com.hanbang.gangyu.R;
import com.hanbang.gycatering.application.MyApplication;
import com.hanbang.gycatering.homepage.BaseActivity;
import com.hanbang.gycatering.utils.HttpInterfaces;
import com.hanbang.gycatering.utils.MyRequestCallBack;
import com.hanbang.gycatering.utils.MyToast;
import com.lidroid.xutils.http.ResponseInfo;
import com.lidroid.xutils.http.client.HttpRequest.HttpMethod;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

public class AnnouncementDetail extends BaseActivity implements OnClickListener {
	private TextView announcement_title, announcement_time,
			announcement_content, announcement_publication;
	private int announcementId;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.announcement_detail);
		initView();
		
	}

	private void initView() {
		// TODO Auto-generated method stub
		((TextView) findViewById(R.id.top_bar_title)).setText("公告详情");
		setBackArrows((ImageView) findViewById(R.id.top_bar_left_image));
		announcement_title = (TextView) findViewById(R.id.announcement_title);
		announcement_time = (TextView) findViewById(R.id.announcement_time);
		announcement_content = (TextView) findViewById(R.id.announcement_content);
		announcement_publication = (TextView) findViewById(R.id.announcement_publication);
		Intent getintent = getIntent();
	  announcementId = getintent.getIntExtra("announcementId", 0);
	  getDetailData();
	}

	private void getDetailData() {
		// TODO Auto-generated method stub
		((MyApplication) getApplicationContext()).httpUtils.send(
				HttpMethod.GET, HttpInterfaces.noticedetails+"&afficheId="+announcementId,
				new MyRequestCallBack<String>(AnnouncementDetail.this,
						getString(R.string.loadding)) {
					@Override
					public void onSuccess(ResponseInfo<String> responseInfo) {
						super.onSuccess(responseInfo);
						try {
							JSONObject json = new JSONObject(
									responseInfo.result);
							if (json.getInt("state") == 1) {
								JSONObject infor = json.getJSONObject("info");
								announcement_title.setText(infor.getString("title"));
								announcement_time.setText(infor.getString("time"));
								announcement_content.setText(infor.getString("content"));
								announcement_publication.setText(infor.getString("source"));
							} else {
								MyToast.show(AnnouncementDetail.this, "获取数据失败",
										Toast.LENGTH_SHORT);
							}
						} catch (JSONException e) {
							e.printStackTrace();
							MyToast.show(AnnouncementDetail.this, "获取数据失败",
									Toast.LENGTH_SHORT);
						}
					}
				});
	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {

		default:
			break;
		}
	}
}
